package com.yonyou.iuap.jxzy.service;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonyou.iuap.baseservice.intg.service.GenericIntegrateService;
import com.yonyou.iuap.baseservice.intg.support.ServiceFeature;
import com.yonyou.iuap.jxzy.dao.AcceptancePaperMapper;
import com.yonyou.iuap.jxzy.dao.PoundderLiverMapper;
import com.yonyou.iuap.jxzy.entity.PoundderLiver;
import com.yonyou.iuap.utils.Base64Util;
import com.yonyou.uap.ieop.security.exception.BusinessException;

@Service
public class PoundderLiverService extends GenericIntegrateService<PoundderLiver>{

	
	@Autowired
	private PoundderLiverMapper mapper;
	
	@Autowired
	private AcceptancePaperMapper acceptancePaperMapper;
	
	public PoundderLiver selectAllParam(Map<String, Object> map) throws UnsupportedEncodingException, BusinessException {
		
		String vdef5=null;
		for(String key:map.keySet()){//序列号解密  需求更改  不要解密,不要删除TODO
			String def5Vlaue=(String) map.get(key);
			//vdef5=new String(Base64Util.decode(vlaue));
			vdef5=def5Vlaue;
		}
		map.put("vdef5", vdef5);
		
		String pk_poundbill=mapper.getPK_Poundbill(vdef5);
		if (pk_poundbill==null) {
			throw new BusinessException("该磅单不存在");
		}
		
		/*List<String> weiCompleMarkList=mapper.getPoundStatus(vdef5);
		
		if (weiCompleMarkList.size()>0 && weiCompleMarkList.get(0)!=null) {
			for (int i = 0; i < weiCompleMarkList.size(); i++) {
				String weiCompleMark=weiCompleMarkList.get(i);
				if (weiCompleMark=="未完成状态") {
					 poundderLiver=mapper.selectAllParam(map);
				}else {
					throw new BusinessException("该磅单不属于未完成状态");
				}
			}
		}*/
		
		//判断国内废纸验收是否数据（是否存在）
		List<String> isFirst=acceptancePaperMapper.getIsFirst(vdef5);
		//获取叉车工工号（第一人称的）
		String forkliftNo=acceptancePaperMapper.getForkliftNo(vdef5);
		//获取测水仪数据(最新的一条数据)
		List<String> averagewaterratio=mapper.getAveragewaterratio(pk_poundbill);
		
		//List<PoundderLiver> list=mapper.selectAllParam(map);
		PoundderLiver poundderLiver=mapper.selectAllParam(map);
		//是否第一人称
		if (isFirst.size()==0) {
			poundderLiver.setIsFirst("Y");
		}else {
			poundderLiver.setIsFirst("N");
		}
		//水分仪测水
		if (averagewaterratio.size()==0) {
			poundderLiver.setAveragewaterratio("0");
		}else {
			String water=averagewaterratio.get(0);
			poundderLiver.setAveragewaterratio(water);
		}
		//叉车工工号
		if (forkliftNo==null) {
			poundderLiver.setForkliftNo(null);
		}else {
			poundderLiver.setForkliftNo(forkliftNo);
		}
		poundderLiver.setPk_poundbill(pk_poundbill);
		return poundderLiver;
	}

	@Override
	protected ServiceFeature[] getFeats() {
		// TODO Auto-generated method stub
		return null;
	}

}
